<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-xs-12">
		<div class="btn-group m-b-1" role="group">
			<?php echo admin_tab_active($menu['user']['tab'], 'list');?>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-md-2 m-b-sm">
		<select id="srchtype" value="<?php echo $srchtype; ?>" class="form-control">
			<option value="username" <?php if($srchtype=='username'){echo 'selected';}?>>用户名</option>
		</select>
	</div>
	<div class="col-md-2 m-b-sm">
		<input type="text" id="keyword" placeholder="关键字" value="<?php echo $keyword; ?>"  class="form-control" />
	</div>
	<div class="col-md-2 m-b-sm">
		<button id="search" class="form-control btn btn-primary">搜索商户</button>
	</div>
	<div class="col-md-3 m-b-sm">
		<input type="text" id="proxy" placeholder="代理名称" value="<?php echo $parent; ?>"  class="form-control" />
	</div>
	<div class="col-md-2 m-b-sm">
		<button id="searchProxy" class="form-control btn btn-success">搜索代理</button>
	</div>
	<div class="col-md-1 m-b-sm">
		<a class="btn btn-info" href="<?php echo $url_export;?>">导出</a>
	</div>
</div>

<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="table-responsive">
				<table class="table" style="min-width: 800px">
					<thead>
						<tr>
							<th class="text-center">删除</th>
							<th class="text-center">用户名</th>
							<th class="text-center">管理</th>
							<th class="text-center">代理</th>
							<th class="text-center">上级代理</th>
							<th class="text-center">费率</th>
							<th class="text-center">余额</th>
							<th class="text-center">累计流水</th>
							<th class="text-center">状态</th>
							<th class="text-center">银行开关</th>
							<th class="text-center">登录IP</th>
							<th class="text-center">登录时间</th>
							<th class="text-center">操作</th>
						</tr>
					</thead>
					<tbody id="userlist">
						<?php if($users){foreach($users as $_user){ ?>
						<?php $_proxy = user_read($_user['parent']); ?>
						<tr uid="<?php echo $_user['uid']; ?>">
							<td class="text-center"><input type="checkbox" name="delete" /></td>
							<td class="text-center"><?php echo $_user['username']; ?></td>
							<td class="text-center"><?php echo $_user['is_admin']==1 ? '<span style="color:#27ae60;">是</span>' : '<span style="color:#ea413c;">否</span>';?></span></td>
							<td class="text-center"><?php echo $_user['is_proxy']==1 ? '<span style="color:#27ae60;">是</span>' : '<span style="color:#ea413c;">否</span>';?></span></td>
							<td class="text-center"><a href="<?php echo url('user-list').'?parent='.$_proxy['username'];?>"><?php echo $_proxy['username']; ?></a></td>
							<td class="text-center"><?php echo $_user['rate']; ?></td>
							<td class="text-center"><?php echo round($_user['coin'],3); ?> 元</td>
							<td class="text-center"><?php echo round($_user['tj_pay'],2); ?> 元</td>
							<td class="text-center"><?php echo $_user['is_open']==1 ? '<span style="color:#27ae60;">审核通过</span>' : '<span style="color:#e74c3c;">待审核</span>'; ?></td>
							<td class="text-center"><?php echo $_user['bank_open']==1 ? '<span style="color:#27ae60;">开</span>' : '<span style="color:#e74c3c;">关</span>'; ?></td>
							<td class="text-center"><?php echo $_user['login_ip']; ?></td>
							<td class="text-center"><?php echo date('m-d H:i',$_user['login_time']); ?></td>
							<td class="text-center">
								<a href="<?php echo url("user-update-$_user[uid]"); ?>">编辑</a>
								<a href="<?php echo url("user-rate-$_user[uid]"); ?>">费率</a>
								<a data-id="<?php echo $_user['uid']; ?>" onclick="recharge(this)">充值</a>
							</td>
						</tr>
						<?php }} ?>
						<tr>
                          	<td class="text-center" colspan="6">合计</td>
                          	<td class="text-center"><?php echo round($total['coin_total'], 3); ?> </td>
                          	<td class="text-center"><?php echo round($total['tj_pay_total'], 2); ?> </td>
                          	<td class="text-center" colspan="5">&nbsp;</td>
                        </tr>
					</tbody>
				</table>
			</div>
			<hr class="m-t-0" />
			<p><button class="btn btn-sm m-l-1" id="confirm">删除</button></p>
		</div>
		<nav class="text-center"><ul class="pagination"><?php echo $pagination; ?></ul></nav>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>



<script>
	var layer;
	var form;
//搜索
var jsearch = $("#search");
var jsrchtype = $("#srchtype");
var jkeyword = $('#keyword');
    layui.use('layer', function(){
        layer = layui.layer;
    });
    layui.use('form', function() {
        form = layui.form;
        form.render();
        form.on('submit(rechargeFilter)', function(data){
            $.ajax({
                type: "post",
                data:data.field,
                async: false,
                url: "<?php echo url('api-recharge'); ?>",
                success: function (data) {
                    if (data.status){
                        layer.close(layer.index);
                        layer.msg(data.data+'<i class="layui-icon layui-icon-face-smile" style="font-size: 30px; color: #1E9FFF;"></i> ');

                        window.setTimeout("timeO()",1000)
                    }else {
                        layer.msg(data.data+'<i class="layui-icon layui-icon-face-smile" style="font-size: 30px; color: #1E9FFF;"></i> ');
                    }
                }
            });
            return false;
        });
    });

    function timeO()
	{
        window.location.reload();
	}

jsearch.on('click', function(){
	var srchtype = jsrchtype.val();
	srchtype = srchtype ? srchtype : 'uid';
	var keyword = $("#keyword").val();
	var url = xn.url('user-list-'+srchtype+'-'+keyword+'-1');
	window.location = url;
});
jkeyword.on('keydown', function(e) {
	if(e.keyCode == 13) jsearch.trigger('click');
});  
$('#searchProxy').on('click', function(){
	var keyword = $("#proxy").val();
	var url = xn.url('user-list')+'?parent='+keyword;
	window.location = url;
});

function recharge(t) {
	var id = $(t).attr('data-id');
        layer.open({
            type: 1,
            title: '充值金额（加 - 代表扣除金额）',
            id: 'recharge',
            area: ['360px'],
            anim: 1
            ,content: '<form class="layui-form layui-form-pane">\n' +
                '    <div class="layui-form-item">\n' +
                '        <label class="layui-form-label">充值</label>\n' +
                '        <div class="layui-input-block">\n' +
                '            <input type="text" name="recharge" lay-verify="required" placeholder="加上 - 为扣除金额" autocomplete="off" class="layui-input">\n' +
                '            <input type="hidden" name="id" value="'+id+'" lay-verify="required" class="layui-input">\n' +
                '        </div>\n' +
                '    </div>\n' +
                '    <div class="layui-form-item">\n' +
                '        <div class="layui-input-block">\n' +
                '            <button class="layui-btn" lay-submit lay-filter="rechargeFilter">立即提交</button>\n' +
                '        </div>\n' +
                '    </div>\n' +
                '    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->\n' +
                '</form>\n' +
                '\n' +
                '\n'
        });
        form.render();
}

// 删除选中的用户
var jconfirm = $("#confirm");
var juserlist = $('#userlist');
jconfirm.on('click', function(){
	var jchecked = juserlist.find('input[name="delete"]').filter(function(){ return this.checked; });
	if(jchecked.length < 1) return alert("请选择要删除的用户");
	if(!window.confirm("确认删除？")) return false;
	jchecked.each(function() {
		jtr = $(this).parents('tr');
		var uid = jtr.attr('uid');
		$.xpost(xn.url('user-delete'), {uid:uid}, function(code, message) {
			if(code != 0) return $.alert(message);
			jtr.remove();
		});
	});
});

$('#nav_pc li.user, #nav_mobile li.user').tab('show');
</script>